<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>圣经中文版</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/bootstrap-theme.min.css"/>
    <link rel="stylesheet" href="css/docs.min.css"/>
    <style>

        .bs-example button {
            margin-right: 10px;
        }
		.bs-docs-header{
			padding-bottom:50px;
		}
		.bs-docs-header h1, .bs-docs-header p{
			margin-right:0;
		}
        .bs-old:after, .bs-new:after {
            position: absolute;
            top: 15px;
            left: 20px;
            font-size: 12px;
            font-weight: 700;
            color: #959595;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .bs-old:after {
            content: "旧约"
        }

        .bs-new:after {
            content: "新约"
        }

        .color-swatch {
            position: relative;
            margin-bottom: 10px;
            cursor: pointer;
			width:100px;
			height:90px;
        }

        .color-swatch .short {
            color: rgba(251,251,251,0.5);
            font-size: 1.9em;
            float: right;
            margin-right: 7px;
            margin-top: 5px;
            font-weight: bold;
        }

        .color-swatch .title {
            color: #fff;
            background-color: rgba(74, 140, 74, 0.39);
            height: 24px;
            line-height: 24px;
            position: absolute;
            bottom: 0;
            width: 100%;
            text-align: center;
        }
        .label{
            margin-top: 3px;
            display: inline-block;
            width: 58px !important;
        }
        .page-header{
            margin: 0;
        }
        .dropdown-menu{
            height: 300px;
            overflow-x: hidden;
            overflow-y: scroll;
        }
        ul,li{
            list-style: none;
        }
        .reading{
            padding-left: 0;
        }
        .reading li{
            font-size:1.5em;
            border-bottom: 1px dashed #f0f0f0;
            overflow: hidden;
            padding: 10px 0px 0px 0px;
        }
        .reading span{
            float:left;
        }
        .reading p{
            cursor: pointer;
            color:#666;
            padding-left: 66px;
			letter-spacing:2px;
        }

        .quotes{
            font-weight: bold;
            color:#1b6d85 !important;
            font-style: italic;

        }
		.bs-docs-footer{
		 padding-top: 20px;
            padding-bottom: 20px;
            margin-top: 20px;
		}
		.navbar-player {
			color:#5cb85c;
			cursor:pointer;
			display: inline-block;
			height: 50px;
			padding: 15px 15px;
			font-size: 18px;
			line-height: 20px;
		}
		.navbar-player:hover{
			color:#55a556;
		}
		.navbar-player:active{
			color:#55a556;
			padding-top:16px;
			padding-left:17px;
		}
    </style>
</head>

<body>
<!-- Docs master nav -->
<header class="navbar navbar-static-top bs-docs-nav navbar-fixed-top" id="top" role="banner" style="border-bottom:1px solid #6f5499">
    <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#bs-navbar"
                    aria-controls="bs-navbar" aria-expanded="false">
                <span class="sr-only">切换导航</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>

            <a href="javascript:Home()" class="navbar-brand">Bible</a>
        </div>
        <nav id="bs-navbar" class="collapse navbar-collapse">

            <ul class="nav navbar-nav">
                <li class="dropdown">
                    <a id="drop1" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                       aria-haspopup="true" aria-expanded="false">
                        {{OldTestament}}
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="drop1">
                        <li v-for="book in Directories.OldTestaments.book">
                            <a href="javascript:GetBook('{{book.cfn}}',0)">{{book.b}}</a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a id="drop2" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                       aria-haspopup="true" aria-expanded="false">
                        {{NewTestament}}
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="drop1">
                        <li v-for="book in Directories.NewTestaments.book">
                            <a href="javascript:GetBook('{{book.cfn}}',1)">{{book.b}}</a>
                        </li>
                    </ul>
                </li>

            </ul>
            <ul class="nav navbar-nav navbar-right">
				<li class="dropdown">
					<audio id="audio" ended="playEnd()" v-show="!Reading" v-bind:src="!Reading | playerPath"></audio>
					<span v-show="!Reading"  class="navbar-player">					
					<span id="player" class="glyphicon glyphicon-play" aria-hidden="true" onclick="playOrPaused(this)"></span>
					</span>
				</li>
                <li id="fat-menu" class="dropdown">
                    <a id="drop3" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                       aria-haspopup="true" aria-expanded="false">
                        <text v-if="!Verses.c">章节选择</text>
						<text v-else>第{{Verses.c}}章</text>
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="drop3">
                        <li v-for="context in Chapters.verses"><a href="javascript:ChangeVerse({{$index}})">第
                            {{context.c}} 章</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="/">返回首页</a></li>
                    </ul>
                </li>
            </ul>
        </nav>
    </div>
</header>

<div class="bs-docs-header" style="text-align:left; margin-top:51px;">
    <div class="container">
        <h1>神</h1>
        <p>是我们的避难所，是我们的力量，是我们在患难中随时的帮助。</p>
        <p style="text-align: right; font-style:italic">--诗篇46:1</p>
        <p id="topFlag"></p>
    </div>
</div>

<div class="container bs-docs-container">
    <div class="row">
        <div class="col-md-12" role="main">
            <div class="bs-docs-section">
                <div id="divDirectories" v-if="Reading">
                    <div class="bs-example bs-old">
                        <div class="color-swatches">
                            <div v-for="book in Directories.OldTestaments.book" onclick="GetBook('{{book.cfn}}',0)" class="{{$index | brand}}">
                                <div class="short">{{book.a}}</div>
                                <div class="title">{{book.b}}</div>
                            </div>
                        </div>
                    </div>
                    <div class="bs-example bs-new">
                        <div class="color-swatches">
                            <div v-for="book in Directories.NewTestaments.book" onclick="GetBook('{{book.cfn}}',1)" class="{{$index | brand}}">
                                <div class="short">{{book.a}}</div>
                                <div class="title">{{book.b}}</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="divVerses" v-else>
                    <h3 class="page-header">
                       <span class="glyphicon glyphicon-book"></span> {{Chapters.book}} / 第 {{Verses.c}} 章
                    </h3>
                    <ul class="reading">
                        <li v-for="text in Verses.text">
                            <span class="label label-success">{{Verses.c}}:{{text.v}}</span>
                            <p onclick="ChangeStyle(this)">{{text.text}}</p>
                        </li>
                    </ul>

                    <div style="float: left">
                        <button class="btn btn-success" onclick="Pre()">上一节</button>
                    </div>
                    <div style="float: right">
                        <button class="btn btn-success" onclick="Next()">下一节</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<footer class="bs-docs-footer" role="contentinfo">
    <div class="container">

        <ul class="bs-docs-footer-links text-muted">
            <li>当前版本： v1.0.0</li>
            <li>&middot;</li>
            <li>
                <a href="http://www.jidujiao.com/">基督教中文网</a>
            </li>
            <li>&middot;</li>
            <li>
                <a href="http://www.yisa.me/">以撤科技</a>
            </li>
            <li>&middot;</li>
            <li>
                <a href="http://bible.sdacn.org/">圣经资源网</a>
            </li>
            <li>&middot;</li>
            <li>
                <a href="mail:jasstion@gmail.com">联系我</a>
            </li>
        </ul>
    </div>
</footer>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/vue.min.js"></script>
<script>
	var audio;
    var brands = ['brand-primary', 'brand-success', 'brand-info', 'brand-warning', 'brand-danger'];
    var books = {
        Directories: {OldTestaments: {}, NewTestaments: {}},
        Chapters: {},
        Verses: {},
        VerseIndex:0,
        Reading:true,
		OldTestament:'旧约',
		NewTestament:'新约'
    };
    var vm = new Vue({
        el: 'body',
        data: books
    });
    Vue.filter('brand', function (index) {
        index = index % 5;
        return 'color-swatch ' + brands[1];
    });
	Vue.filter('playerPath',function(reading){
		if(reading){
			var bookName=books.Chapters.book.replace(/(^\s*)|(\s*$)/g, '');
			return ['mp3/',bookName,'/',bookName,'第',books.Verses.c,'章.mp3'].join('');
		}
		return '';
	});
    Vue.filter('trim',function(str){
        return str.replace(/(^\s*)|(\s*$)/g, '');
    });
    function GetData(dataUrl, callBack) {
        $.ajax({
            type: "get",
            url: dataUrl,
            async: true,
            success: function (data) {
                callBack(data);
            },
            error: function (err) {
                console.log("获取数据出错：" + err);
            }
        });
    }
    function getDirectories(dataUrl) {

        GetData(dataUrl, function (data) {
            books.Directories.OldTestaments = data.books.Testament[0];
            books.Directories.NewTestaments = data.books.Testament[1];
        });
    }
    function GetBook(cfn,isNew) {
        cfn = "books/" + cfn + ".json";
		
        GetData(cfn, function (data) {
            books.Chapters = data;
            books.Verses = data.verses[0];
            books.Reading=false;
            if(isNew){
				books.OldTestament='旧约';
				books.NewTestament=data.book;
			}else{
				books.OldTestament=data.book;;
				books.NewTestament='新约';
			}
			$('html,body').animate({scrollTop:$('#topFlag').offset().top},1000);
        });
    }
    function ChangeVerse(index) {
        books.VerseIndex=index;
        books.Verses = books.Chapters.verses[index];
        $('html,body').animate({scrollTop:$('#topFlag').offset().top},1000);
    }
    function ChangeStyle(obj){
        $(obj).toggleClass('quotes');
    }
    function Next(){
        var len=books.Chapters.verses.length;
        if(books.VerseIndex<len){
            books.VerseIndex+=1;
        }else{
            books.VerseIndex=len-1;
        }
        ChangeVerse(books.VerseIndex);
    }
    function Pre(){
        if(books.VerseIndex>0){
            books.VerseIndex-=1;
        }else{
            books.VerseIndex=0;
        }
        ChangeVerse(books.VerseIndex);
    }
    function Home(){
        books.Reading=true;
    }
	function playOrPaused(obj){	
		if(audio.paused){
			audio.play();
			$(obj).removeClass('glyphicon-play');
			$(obj).addClass('glyphicon-pause');
			return;
		}
		$(obj).removeClass('glyphicon-pause');
		$(obj).addClass('glyphicon-play');
		audio.pause();
	}
	function playEnd(){
		$('#player').removeClass('glyphicon-pause');
		$('#player').addClass('glyphicon-play');
	}
    $(function () {
		audio=document.getElementById('audio');
        getDirectories("books/books_cuvs.xml.json");

        $('html,body').dblclick(function(){
            $('html,body').animate({scrollTop:$('#top').offset().top},1000);
        })

    });
</script>
</body>

</html>